home *** CD-ROM | disk | FTP | other *** search
/ Workbench Design / WB Collection.iso / datatypes / font_dt / src / classbase.c next >
C/C++ Source or Header  |  1996-04-07  |  4KB  |  125 lines

  1. /*
  2. **    classbase.c - implementation of standard function for Font DataType class
  3. **    Copyright © 1995 Michael Letowski
  4. */
  5.  
  6. #include <exec/types.h>
  7. #include <exec/execbase.h>
  8. #include <exec/libraries.h>
  9. #include <exec/semaphores.h>
  10. #include <dos/dos.h>
  11. #include <support/types.h>
  12.  
  13. #include <proto/exec.h>
  14. #include <proto/intuition.h>
  15.  
  16. #include "classbase.h"
  17. #include "dispatch.h"
  18.  
  19. #define INT_NAME        "intuition.library"
  20. #define INT_VERN        39
  21. #define GFX_NAME        "graphics.library"
  22. #define GFX_VERN        39
  23. #define DOS_NAME        "dos.library"
  24. #define DOS_VERN        39
  25. #define UTIL_NAME        "utility.library"
  26. #define UTIL_VERN        39
  27. #define DT_NAME            "datatypes.library"
  28. #define DT_VERN            39
  29. #define DF_NAME            "diskfont.library"
  30. #define DF_VERN            39
  31. #define PDT_NAME        "datatypes/picture.datatype"
  32. #define PDT_VERN        39
  33.  
  34. ASM Class *ObtainFontEngine(R_A6 struct ClassBase *cb)
  35. {
  36.     return(cb->cb_Class);
  37. }    /* ObtainREKOEngine */
  38.  
  39. ASM struct ClassBase *LibInit(R_D0 struct ClassBase *cb, R_A0 BPTR segList,
  40.                                                             R_A6 struct Library *sysBase)
  41. {
  42.     cb->cb_SegList=segList;
  43.     cb->cb_SysBase=(struct ExecBase *)sysBase;
  44.     InitSemaphore(&cb->cb_Lock);                                    /* Initialize locking */
  45.     try(cb->cb_IntuitionBase=OpenLibrary(INT_NAME,INT_VERN),    NO_INT);
  46.     try(cb->cb_GfxBase=OpenLibrary(GFX_NAME,GFX_VERN),                NO_GFX);
  47.     try(cb->cb_DOSBase=OpenLibrary(DOS_NAME,DOS_VERN),                NO_DOS);
  48.     try(cb->cb_UtilityBase=OpenLibrary(UTIL_NAME,UTIL_VERN),    NO_UTIL);
  49.     return(cb);
  50.  
  51.     except(FOO,                );
  52.     except(NO_UTIL,    CloseLibrary(cb->cb_UtilityBase));
  53.     except(NO_DOS,    CloseLibrary(cb->cb_DOSBase));
  54.     except(NO_GFX,    CloseLibrary(cb->cb_GfxBase));
  55.     except(NO_INT,    CloseLibrary(cb->cb_IntuitionBase));
  56.     return(NULL);
  57. }    /* LibInit */
  58.  
  59. ASM struct ClassBase *LibOpen(R_A6 struct ClassBase *cb)
  60. {
  61.     ObtainSemaphore(&cb->cb_Lock);                                /* Protect library base */
  62.     fclr(cb->cb_Lib.lib_Flags,LIBF_DELEXP);                /* No delayed expunge */
  63.  
  64.     if(cb->cb_Lib.lib_OpenCnt==0 && cb->cb_Class==NULL)
  65.     {                                                                                            /* First open */
  66.         try(cb->cb_DataTypesBase=OpenLibrary(DT_NAME,DT_VERN),        NO_DT);
  67.         try(cb->cb_DiskfontBase=OpenLibrary(DF_NAME,DF_VERN),            NO_DF);
  68.         try(cb->cb_SuperClassBase=OpenLibrary(PDT_NAME,PDT_VERN),    NO_PDT);
  69.         try(cb->cb_Class=InitClass(cb),                                                        NO_CLASS);
  70.     }
  71.  
  72.     cb->cb_Lib.lib_OpenCnt++;                                            /* Mark successfull opening */
  73.     ReleaseSemaphore(&cb->cb_Lock);                                /* Data modified */
  74.     return(cb);                                                                        /* Return success */
  75.  
  76.     except(FOO,                );
  77.     except(NO_CLASS,FreeClass(cb->cb_Class));
  78.     except(NO_PDT,    CloseLibrary(cb->cb_SuperClassBase));
  79.     except(NO_DF,        CloseLibrary(cb->cb_DiskfontBase));
  80.     except(NO_DT,        CloseLibrary(cb->cb_DataTypesBase));
  81.     ReleaseSemaphore(&cb->cb_Lock);                                /* Unlock base */
  82.     return(NULL);                                                                    /* Return failure */
  83. }    /* LibOpen */
  84.  
  85. ASM BPTR LibClose(R_A6 struct ClassBase *cb)
  86. {
  87.     BPTR Seg=0;
  88.  
  89.     ObtainSemaphore(&cb->cb_Lock);                                /* Protect library base */
  90.     if(cb->cb_Lib.lib_OpenCnt)
  91.         cb->cb_Lib.lib_OpenCnt--;                                        /* Decrease open count */
  92.     if(cb->cb_Lib.lib_OpenCnt==0 && cb->cb_Class)
  93.         if(FreeClass(cb->cb_Class))
  94.         {
  95.             cb->cb_Class=NULL;
  96.             CloseLibrary(cb->cb_SuperClassBase);
  97.             CloseLibrary(cb->cb_DiskfontBase);
  98.             CloseLibrary(cb->cb_DataTypesBase);
  99.         }
  100.         else
  101.             fset(cb->cb_Lib.lib_Flags,LIBF_DELEXP);
  102.     ReleaseSemaphore(&cb->cb_Lock);                                /* Unlock base */
  103.     if(ftst(cb->cb_Lib.lib_Flags,LIBF_DELEXP))        /* Delayed expunge set? */
  104.         Seg=LibExpunge(cb);
  105.     return(Seg);
  106. }    /* LibClose */
  107.  
  108. ASM BPTR LibExpunge(R_A6 struct ClassBase *cb)
  109. {
  110.     BPTR Seg=0;
  111.  
  112.     if(cb->cb_Class==NULL)                                                /* No accesors? */
  113.     {
  114.         Seg=cb->cb_SegList;
  115.         Remove((struct Node *)cb);                                    /* Remove from library list */
  116.         CloseLibrary(cb->cb_UtilityBase);
  117.         CloseLibrary(cb->cb_DOSBase);
  118.         CloseLibrary(cb->cb_GfxBase);
  119.         CloseLibrary(cb->cb_IntuitionBase);
  120.         FreeMem((APTR)((ULONG)(cb)-(ULONG)(cb->cb_Lib.lib_NegSize)),
  121.                         cb->cb_Lib.lib_NegSize + cb->cb_Lib.lib_PosSize);
  122.     }
  123.     return(Seg);
  124. }    /* LibExpunge */
  125.